home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / zmdm.zoo / rz.c < prev    next >
C/C++ Source or Header  |  1991-04-27  |  29KB  |  1,504 lines

  1. /*
  2.  *                ACKNOWLEDGEMENTS
  3.  *
  4.  *    ZMDM was derived from rz/sz for Unix  posted by 
  5.  *    Chuck Forsberg (...!tektronix!reed!omen!caf ). We
  6.  *    thank him for his excellent code, and for giving
  7.  *    us permission to use and distribute his code and
  8.  *    documentation.
  9.  *
  10.  *    Atari St version by:
  11.  *    Jwahar Bammi
  12.  *     bang:   {any internet host}!dsrgsun.ces.CWRU.edu!bammi
  13.  *     domain: bammi@dsrgsun.ces.CWRU.edu
  14.  *    GEnie:    J.Bammi
  15.  */
  16.  
  17. #include "config.h"
  18. #define RVERSION "rz 3.01 5-25-89"
  19. #define RSTVERSION "$Revision: 1.72 $ $Date: 1991/04/27 22:12:49 $"
  20. #define OS    "Unix V7/BSD"
  21.  
  22. /* #define RDEBUG */            /* a lot of debugging garb */
  23.  
  24. /*
  25.  *    ATARI ST series implementation notes:
  26.  *
  27.  *        - the following command line options were removed as they
  28.  *          were either  not applicable to the ST environment or
  29.  *          were not deemed reasonable (by me - ofcourse).
  30.  *            1    Not Applicable here as we have a seperate
  31.  *                serial port.
  32.  *            7    In this day and age? Forget it, get another m/c.
  33.  *            a/b    Ascii/Binary - the receive mode (if not
  34.  *                over-ridden by the sender) is automatically
  35.  *                selected depending on the extention given
  36.  *                in the incoming file name. This idea was
  37.  *                present in earlier rz/sz, i wonder why such
  38.  *                a convenient feature was dropped (Chuck ??).
  39.  *                This feature is relevant to ZMODEM only in rz,
  40.  *                as the sender determines the file mode in
  41.  *                XMODEM/YMODEM transfers.
  42.  *                B    Note that `B' has a special meaning.
  43.  *                Specifying -B will force override to
  44.  *                binary mode for each incoming file. Useful
  45.  *                 when doing St-to-St transfers.
  46.  *            D    There is no /dev/null on the ST's
  47.  *            u    not applicable to TOS. Upper and lower
  48.  *                case file names are the same. All the
  49.  *                applicable routines like uncap() and
  50.  *                IsAnyLower() were zapped.
  51.  *
  52.  *        - The    [-][v]rzCOMMAND style of invocation was dropped
  53.  *          as there is no good way to do pipes without the 
  54.  *          microRtx kernal. All references to Pipe and popen()
  55.  *          were zapped.
  56.  *        - Verbose is always set to 2 by automatically, as we know that
  57.  *          stdout != stderr. This can be overridden
  58.  *          by specifying -q to ensure that Verbose = 0
  59.  *        - The idea of a PUBDIR and Restricted paths in the origonal
  60.  *          code  was dropped totally as it is not applicable
  61.  *          to the single owner ST environment. 1 man 1 machine.
  62.  *        - CRCTABLE is default always, hey we have plenty of memory!.
  63.  *        - LOGFILE renamed to 'rzlog/szlog' as we don't always have
  64.  *          a meaningful environment to pick up TMPDIR from (like when
  65.  *          running from the desktop).
  66.  *            - When a subdirectory in an incoming path name is not
  67.  *          present it is created.
  68.  *        - The file mode transmitted is 0S00 where S is derived from
  69.  *          the Read/Write attribute of the file on the ST
  70.  *        - When a file mode is received, only the owner bits are
  71.  *          are checked. If it was read only (r--) on the Unix sytem
  72.  *          then it is given read only attribute on the ST, read-write
  73.  *          otherwise.
  74.  *        - Of course all the I/O was completely redone on the ST.
  75.  *        - You will find two versions of VARARGS routines like log,
  76.  *          one that takes int args, and the other that takes long
  77.  *          (address) args, since sizeof(int) != sizeof(long)
  78.  *          and sizeof(int) != sizeof(pointer) on the ST.
  79.  *
  80.  *    ST v1.01
  81.  *     added support for 32 bit CRC's for Zmodem ++jrb
  82.  *
  83.  *    ST v1.2
  84.  *     added -B ++jrb
  85.  *     added all the recursive stuff
  86.  *     added remote
  87.  */
  88.         
  89. /*% cc -DNFGVMIN -DCRCTABLE -K -O % -o rz; size rz
  90.  *
  91.  * rz.c By Chuck Forsberg
  92.  *
  93.  *    cc -O rz.c -o rz        USG (3.0) Unix
  94.  *     cc -O -DV7  rz.c -o rz        Unix V7, BSD 2.8 - 4.3
  95.  *
  96.  *    ln rz rb            For either system
  97.  *
  98.  *    ln rz /usr/bin/rzrmail        For remote mail.  Make this the
  99.  *                    login shell. rzrmail then calls
  100.  *                    rmail(1) to deliver mail.
  101.  *
  102.  *        define CRCTABLE to use table driven CRC
  103.  *
  104.  *  Unix is a trademark of Western Electric Company
  105.  *
  106.  * A program for Unix to receive files and commands from computers running
  107.  *  Professional-YAM, PowerCom, YAM, IMP, or programs supporting XMODEM.
  108.  *  rz uses Unix buffered input to reduce wasted CPU time.
  109.  *
  110.  * Iff the program is invoked by rzCOMMAND, output is piped to 
  111.  * "COMMAND filename"
  112.  *
  113.  *  Some systems (Venix, Coherent, Regulus) may not support tty raw mode
  114.  *  read(2) the same way as Unix. ONEREAD must be defined to force one
  115.  *  character reads for these systems. Added 7-01-84 CAF
  116.  *
  117.  *  Alarm signal handling changed to work with 4.2 BSD 7-15-84 CAF 
  118.  *
  119.  *  NFGVMIN Added 1-13-85 CAF for PC-AT Xenix systems where c_cc[VMIN]
  120.  *  doesn't seem to work (even though it compiles without error!).
  121.  *
  122.  *  USG UNIX (3.0) ioctl conventions courtesy  Jeff Martin
  123.  */
  124.  
  125.  
  126. #include "zmdm.h"
  127. #include "common.h"
  128. #include "zmodem.h"
  129.  
  130. static unsigned long SaveIntr;
  131.  
  132. #ifndef Vsync             /* Atari forgot these in osbind.h */
  133. #define Vsync()    xbios(37)
  134. #endif
  135.  
  136. #ifndef Supexec
  137.         /* Some versions of osbind don't define Supexec */
  138. #define Supexec(X) xbios(38,X)
  139. #endif
  140.  
  141. #if (MWC || MANX || __GNUC__)
  142. extern FILE  *fopen();
  143. #else
  144. extern FILE  *fopen(), *fopenb();
  145. #endif
  146.  
  147. #ifndef STANDALONE
  148. #define RETURN return
  149. #else
  150. static void RETURN();
  151. void bibis(n) int n; {} /* dummy */
  152. #endif 
  153.  
  154. static long start_time;
  155.  
  156. #ifndef STANDALONE
  157. /* called by simulated signal interrupt or terminate to clean things up */
  158. void bibi(n)
  159. int n;
  160. {
  161.  
  162.     if (Zmodem)
  163.         zmputs(Attn);
  164.     canit(); mode(0);
  165.     fprintf(STDERR, "\r\nrz: caught signal %d; exiting", n);
  166.     if (fout != -1)
  167.     {
  168.         if (stfclose(fout) != 0)
  169.         {
  170.             fprintf(STDERR, "\r\nfile close ERROR\n");
  171.         }
  172.         fout = (-1);
  173.  
  174.     }
  175.  
  176. #ifdef RDEBUG
  177.     if (logf != (FILE *)NULL)
  178.         fclose(logf);
  179. #endif
  180.     aexit(128+n);
  181. }
  182. #endif
  183.  
  184. #ifdef STANDALONE
  185. int main(argc, argv)
  186. #else
  187. int dorz(argc, argv)
  188. #endif /* STANDALONE */
  189. int argc;
  190. char **argv;
  191. {
  192.     register char *cp;
  193.     register int npats;
  194.     char **patts;
  195.     int exitcode;
  196.  
  197. #ifdef STANDALONE
  198. #if (MWC || __GNUC__)
  199. #ifdef MWC
  200.     extern char *lmalloc();
  201. #else
  202. #define lmalloc malloc
  203.     extern void *lmalloc(unsigned long);
  204. #endif
  205. #endif
  206.  
  207.     /* Set up Dta */
  208.     Fsetdta(&statbuf);
  209.  
  210.     /* Get screen rez */
  211.     rez = Getrez();
  212.     drv_map = Drvmap();
  213.  
  214. #if (MWC || MANX || __GNUC__)
  215. #ifndef DYNABUF
  216. #if (MWC || __GNUC__)
  217.     if((bufr = (unsigned char *)lmalloc((unsigned long)BBUFSIZ))
  218.                      == (unsigned char *)NULL)
  219. #else
  220.     if((bufr = (unsigned char *)Malloc((unsigned long)BBUFSIZ))
  221.                      == (unsigned char *)NULL)
  222. #endif
  223. #else
  224.     if((bufr = dalloc()) == (unsigned char *)NULL)
  225. #endif /* DYNABUF */
  226.     {
  227. #ifdef REMOTE
  228.         Bauxws("Sorry, could not allocate enough memory\r\n");
  229. #else
  230.         Bconws("Sorry, could not allocate enough memory\r\n");
  231. #endif
  232.  
  233.         Pterm(4);
  234.     }
  235. #else /* MWC || MANX */
  236. #ifdef DYNABUF
  237.     if((bufr = dalloc()) == (unsigned char *)NULL)
  238.     {
  239. #ifdef REMOTE
  240.         Bauxws("Sorry, could not allocate enough memory\r\n");
  241. #else
  242.         Bconws("Sorry, could not allocate enough memory\r\n");
  243. #endif
  244.         Pterm(5);
  245.     }
  246. #endif /* DYNABUF */
  247. #endif /* MWC || MANX */
  248.  
  249. #ifndef REMOTE
  250.     STDERR = stderr;
  251. #else
  252. #ifndef DLIBS
  253.     if((STDERR = fopen("aux:", "rw")) == (FILE *)NULL)
  254.     {
  255.         Bauxws("Could not Open Aux Stream for Stderr\r\n");
  256.         finish();
  257.     }
  258.     setbuf(STDERR, (char *)NULL);
  259. #else
  260.     STDERR = stdaux;
  261. #endif /* DLIBS */
  262.     
  263. #endif /* REMOTE */
  264.  
  265.     {
  266.         int speed;
  267.         speed = getbaud();
  268.         Baudrate = BAUD_RATE(speed);
  269.         SetIoBuf();
  270.         Rsconf(speed, 0,-1,-1,-1,-1);
  271.         Vsync(); Vsync();
  272.     }
  273.  
  274. #endif /* STANDALONE */
  275.  
  276.     SendType = 0;
  277.     Rxtimeout = 100;
  278.     exitcode = 0;
  279.  
  280.     initz();
  281.  
  282. #ifndef STANDALONE
  283.     chkinvok(argv[0]);     /* if called as  'rb' set flag */
  284. #else
  285.     Progname = "rz";
  286. #endif
  287.  
  288.     npats = 0;
  289.     SaveIntr = Setexc(0x0102, -1L);
  290.     BusErr   = Setexc(2, -1L);
  291.     AddrErr  = Setexc(3, -1L);
  292.     vdebug = 0;
  293.  
  294.     while (--argc)
  295.     {
  296.         cp = *++argv;
  297.         if (*cp == '-')
  298.         {
  299.             while( *++cp)
  300.             {
  301.                 switch(*cp)
  302.                 {
  303.                 case '+':
  304.                     Lzmanag = ZMAPND; break;
  305.                 case 'B':
  306.                     ForceBinary=TRUE; break;
  307.                 case 'c':
  308.                     Crcflg=TRUE; break;
  309.                 case 'D':
  310.                     Nflag = TRUE; break;
  311.                 case 'e':
  312.                     Zctlesc = 1; break;
  313.                 case 'p':
  314.                     Lzmanag = ZMPROT;  break;
  315.                 case 'q':
  316.                     Quiet=TRUE; Verbose=0; break;
  317.                 case 't':
  318.                     if (--argc < 1) {
  319.                         rusage();
  320.                         RETURN(1);
  321.                     }
  322.                     Rxtimeout = atoi(*++argv);
  323.                     if (Rxtimeout<10 || Rxtimeout>1000)
  324.                     {
  325.                         rusage();
  326.                         RETURN(1);
  327.                     }
  328.                     break;
  329.                 case 'w':
  330.                     if (--